package com.untour.im.codec.protocol.handler;

import com.alibaba.fastjson2.JSON;
import com.untour.im.codec.protocol.packet.request.body.HeartBeatRequestPacketData;
import com.untour.im.codec.protocol.packet.response.ResponsePacketCodec;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class HeartBeatServerHandler extends SimpleChannelInboundHandler<HeartBeatRequestPacketData> {
    public static final HeartBeatServerHandler INSTANCE = new HeartBeatServerHandler();

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, HeartBeatRequestPacketData requestPacketData) {
        log.info("服务端接收到客户端心跳，【{}】", JSON.toJSONString(requestPacketData));
        ResponsePacketCodec.INSTANCE.sendHeartBeatResponseMessage(ctx,requestPacketData.getMessageBody().getMessageId());
    }
}
